******************************************
MACRO for CPS Survey Years 1968-1972 
to calculate State Tax Liabilities using
IncTaxCalc SAS Program
Program 3 of 4

5/3/10: NOTE, DID NOT EDIT THIS PROGRAM, RATHER, TOOK THE OUTPUT THAT TOM CREATED: TAXS* SAS DATASETS

******************************************;
/*
libname taxsim "C:\Documents and Settings\Tommy\My Documents\taxsim";
filename tax68 'C:\Documents and Settings\Tommy\My Documents\taxsim\taxsim1968out.txt';
filename tax69 'C:\Documents and Settings\Tommy\My Documents\taxsim\taxsim1969out.txt';
filename tax70 'C:\Documents and Settings\Tommy\My Documents\taxsim\taxsim1970out.txt';
filename tax71 'C:\Documents and Settings\Tommy\My Documents\taxsim\taxsim1971out.txt';
filename tax72 'C:\Documents and Settings\Tommy\My Documents\taxsim\taxsim1972out.txt';
*/
**********************************************************************
Before beginning this program make sure the following 
files are placed in your taxsim library location: 

1) IncTaxCalc.SAS (SAS program for Calculating State Tax Liabilities
2) IncTaxState.dat (data file that goes along with SAS Program)
3) IncTaxfed.dat (data file that goes along with SAS Program)

It should be noted that only 1 change needs to be made to 
the IncTaxCalc.SAS program.  It involves the SAS log and having it 
be written to another file.  To avoid this problem I have commented 
out the command that would have the log written to another file: 
(Lines 155-156 right before III Pathnames Section);
/*
PROC PRINTTO LOG=" &outputpath.\IncTaxCalc.log " NEW;
RUN;
*/
*I had problems with the program before I made the above change
after that it runs fine
**********************************************************************;
%macro taxfed6872(yr);
***********************************
INC Tax Calculator Program
***********************************;
data inc&yr;
set cpsdata.taxsim&yr;            /* JH's edit*/
fedyear=ref_year;
stateyear=ref_year;
kids1=0;
income=0;
div2=0;
int2=0;
pension2=0;
ui2=0;
age=0;
agesp=0;
blind=0;
businc1=0;
businc2=0;
farminc1=0;
farminc2=0;
ltcg1=0;
ltcg2=0;
othcg1=0;
othcg2=0;
teint1=0;
teint2=0;
rentinc1=0;
rentinc2=0;
ssben2=0;
partscorp1=0;
partscorp2=0;
othinc1=0;
othinc2=0;
othadj1=0;
othadj2=0;
charity=0;
charcg=0;
intpaid=0;
invint=0;
stinctax=0;
proptax=0;
salestax=0;
taxnodetail=0;
medexp=0;
casualty=0;
movex=0;
busex=0;
miscdedlim=0;
omiscded=0;
childcare=0;
fdcred=0;
otaxpref=0;
oamtadj=0;
avglaginc=0;
psincome=0;
psded=0;
rentpay=0;
homeval=0;
run;

data final&yr;
set inc&yr;
if filestat=1 then filetype='s';
else if filestat=2 then filetype='m';
else if filestat=3 then filetype='h';
drop fill filestat ;
run;


data final&yr;
set final&yr;
* RENAME VARIABLES SO THEY WORK WITH THE INCTAXCALC PROGRAM;
rename ref_year=year; 
rename filetype=filertype;
rename totdep=deps;
rename kid_eitc=kids2;
rename kid_fcc=kids3;
rename num_gt65=agenum;
rename taxinc=wagsal1;
rename tfu_wifi=wagsal2;
rename inc9=div1;
rename inc10=int1;
rename inc11=pension1;
rename inc18=ui1;
rename inc12=ssben1;
*rename ts_state=state;
run;
%mend taxfed6872;
%taxfed6872(1968);
%taxfed6872(1969);
%taxfed6872(1970);
%taxfed6872(1971);
%taxfed6872(1972); 

*Create 1 dataset to run through IncTaxCalc;
data statetax;
set final1968 final1969 final1970 final1971 final1972;
run;



filename macs "C:\Users\worri\Dropbox\Poverty\SAS Programs CPS 68-72" ;
options mautosource ;
options sasautos=macs ;

* READ IN THE INCTAXCALC PROGRAM;
%include 'C:\Users\worri\Dropbox\Poverty\SAS Programs CPS 68-72\IncTaxCalc.sas';
%IncTaxCalc(
programpath=C:\Users\worri\Dropbox\Poverty\SAS Programs CPS 68-72,
inputpath=C:\Users\worri\Dropbox\Poverty\SAS Programs CPS 68-72,
outputpath=C:\Users\worri\Dropbox\Poverty\taxsim,
inputset=statetax,
outputset=upout,
fedparam=IncTaxFed,
stateparam=IncTaxState,
loadparam=1,
mtrvar=ltcg1,
incrementkind=dollar,
incrementquantity=0.1, 
detail=0,
inputformat=2,
outputformat=1,
reverseMTR=1,
checkMTR=0.9,
statecodetype=1,
yearstart=67,
cbinclude=1,
local=1 ) ;
run;
proc means data=taxsim.upout;
run;

%macro taxfed6872a(yr,dir);
*Create different datasets for different years;

data Inc&yr;
set taxsim.upout;
if year=&yr-1;
keep id taxs;
run;

/*******************/
/* JH's edit*/
data taxsim&yr;
set taxsim.taxs&yr;
rename CaseID=id;
run;

data taxsim&yr;
set taxsim&yr;
keep id year ftl ts_fica;
run;
/*******************/

proc sort data=inc&yr;
by id;
run;
proc sort data=taxsim&yr;
by id;
run;

data meg&yr;
merge taxsim&yr inc&yr;
by id;
run;

proc means data=meg&yr;
run;

data taxsim.taxs&yr;
set meg&yr;
run;

%mend taxfed6872a;
%taxfed6872a(1968,tax68);
%taxfed6872a(1969,tax69);
%taxfed6872a(1970,tax70);
%taxfed6872a(1971,tax71);
%taxfed6872a(1972,tax72); 

